package com.erp.serviceImpl.financeServiceImpl;

import com.erp.dao.IncomeMapper;
import com.erp.service.financeService.IncomeService;
import com.erp.pojo.Income;
import com.erp.utils.Msg;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.io.Serializable;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Description: TeamProject
 * Created by ${ZhangZhenJun}on 2019/1/10.
 */
@Service
public class IncomeServiceImpl implements IncomeService , Serializable {

    @Autowired
    private IncomeMapper incomeMapper;

    @Override
    public Msg selectIncomeService(int pageNum,int pageSize,String billNo, Date billTimeBefore, Date billTimeBack,String type) {

        /*定义分页*/
        PageHelper.startPage(pageNum,pageSize);
        /*条件查询*/
        Map<String,Object> map = new HashMap<>();
        map.put("billNo",billNo);
        map.put("billTimeBefore",billTimeBefore);
        map.put("billTimeBack",billTimeBack);
        map.put("type",type);
        List<Income> incomeList = incomeMapper.selectIncomeAll(map);

        System.out.println("==================="+incomeList+"============================");

        /*进行分页*/
        PageInfo incomePageInfo = new PageInfo(incomeList);
        /*返回结果集*/
        Msg msg = new Msg();
        msg.setCode(0);
        msg.setMsg("");
        msg.setCount(incomePageInfo.getTotal());
        msg.setData(incomePageInfo.getList());
        return msg;
    }

    @Override
    public void insertIncomeAccounthead(Income income) {
        incomeMapper.insertIncomeAccounthead(income);
    }

    @Override
    public void insertIncomeInoutitem(Income income) {
        incomeMapper.insertIncomeInoutitem(income);
    }

    @Override
    public void insertIncomeAccount(Income income) {
        incomeMapper.insertIncomeAccount(income);
    }

    @Override
    public void insertIncomeAccountitem(Income income) {
        incomeMapper.insertIncomeAccountitem(income);
    }

    @Override
    public void insertIncomePerson(Income income) {
        incomeMapper.insertIncomePerson(income);
    }

    @Override
    public void insertIncomeSupplier(Income income) {
        incomeMapper.insertIncomeSupplier(income);
    }

    @Override
    public void deleteIncome(Long accountId) {
        incomeMapper.deleteIncome(accountId);
    }
}
